//
// Created by zhuyijun on 2021/9/22.
//

#include <iostream>
#include <list>
#include <algorithm>

using namespace std;

void Show(int);

const int LIM = 10;

int main() {

    int ar[LIM]{
            4, 5, 4, 2, 2, 3, 4, 8, 1, 4
    };
    list<int> la(ar, ar + LIM);
    list<int> lb(la);
    cout << "Original list contents:\n\t";
    for_each(la.begin(), la.end(), Show);
    cout << endl;
    la.remove(4);
    cout << "After using the remove() methond:\n";
    cout << "la:\t";
    for_each(la.begin(), la.end(), Show);
    cout << endl;
    auto last = remove(lb.begin(), lb.end(), 4);
    cout << "After using the remove() function:\n";
    cout << "lb:\t";
    for_each(lb.begin(), lb.end(), Show);
    cout << endl;
    lb.erase(last, lb.end());
    cout << "After using the earse() methond:\n";
    cout << "lb:\t";
    for_each(lb.begin(), lb.end(), Show);
    cout << endl;
    return 0;
}

void Show(int v) {
    cout << v << ' ';
}